<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="12">
            <a-form-model-item label="经办人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlerId">
              <a-input :disabled=formDisabled v-model="model.handlerId" placeholder="请输入经办人"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="经办部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="handlerDeptId">
              <a-input :disabled=formDisabled v-model="model.handlerDeptId" placeholder="请输入经办部门"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="createTime">
              <j-date :disabled=formDisabled placeholder="请选择创建时间" v-model="model.createTime" :show-time="true"
                      date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请授权公司" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyCompany">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.applyCompany" dictCode=""
                                 placeholder="请选择申请授权公司"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请授权部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyDept">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.applyDept" dictCode=""
                                 placeholder="请选择申请授权部门"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="申请授权责任人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyAuthPerson">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.applyAuthPerson" dictCode=""
                                 placeholder="请选择申请授权责任人"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="被委托方（印章保管人）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="trustee">
              <j-dict-select-tag :disabled=formDisabled type="list" v-model="model.trustee" dictCode=""
                                 placeholder="请选择被委托方（印章保管人）"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授权印章开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authDateStart">
              <j-date :disabled=formDisabled placeholder="请选择授权印章开始时间" v-model="model.authDateStart"
                      style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授权印章结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="authDateEnd">
              <j-date :disabled=formDisabled placeholder="请选择授权印章结束时间" v-model="model.authDateEnd" style="width: 100%"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input :disabled=formDisabled v-model="model.projectName" placeholder="请输入项目名称"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="授权范围及授权说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="scopeContent">
              <a-input :disabled=formDisabled v-model="model.scopeContent" placeholder="请输入授权范围及授权说明"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="上传附件" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="upload">
              <j-upload :disabled=formDisabled v-model="model.upload"></j-upload>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'

export default {
  name: 'ErpSealAuthorizationInformationForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {},
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 24 },
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/api/erp/administration/seal/erpSealAuthorizationInformation/add',
        edit: '/api/erp/administration/seal/erpSealAuthorizationInformation/edit',
        queryById: '/api/erp/administration/seal/erpSealAuthorizationInformation/queryById'
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.$refs.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.add;
            method = 'post';
          } else {
            httpurl += this.url.edit;
            method = 'put';
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok');
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>
